/*
 *  Copyright (C) 2017 OrionStar Technology Project
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package com.invengo.library_orionstar;

import android.os.RemoteException;
import android.util.Log;


import com.ainirobot.coreservice.client.speech.SkillCallback;

import me.goldze.mvvmhabit.bus.Messenger;
import me.goldze.mvvmhabit.utils.KLog;

public class SpeechCallback extends SkillCallback {

    private static final String TAG = SpeechCallback.class.getName();

    /**
     * 这里是语音内容反馈：
     * 金
     * 今天天气
     * 今天天气怎么样
     * @param s
     * @throws RemoteException
     */
    @Override
    public void onSpeechParResult(String s) throws RemoteException {
        Messenger.getDefault().send(SpeechEvent.parResult(s),"SPEECH_TO_PAGE");
//        RobotManager.getInstance().onSpeech(SpeechBean.SpeechTag.SPEECH_PAR_RESULT,s);
        Log.i(TAG, " onSpeechParResult:"+ s);
    }

    /**
     * 说话开始
     * @throws RemoteException
     */
    @Override
    public void onStart() throws RemoteException {
        Messenger.getDefault().send(SpeechEvent.start(),"SPEECH_TO_PAGE");
//        RobotManager.getInstance().onSpeech(SpeechBean.SpeechTag.SPEECH_START);
        Log.i(TAG, " onStart");
    }
    /**
     * 说话结束
     * @throws RemoteException
     */
    @Override
    public void onStop() throws RemoteException {
        Messenger.getDefault().send(SpeechEvent.stop(),"SPEECH_TO_PAGE");
    }

    @Override
    public void onVolumeChange(int i) throws RemoteException {
        //LogTools.info(TAG+" onVolumeChange :" + i);
    }

    @Override
    public void onQueryEnded(int i) throws RemoteException {
        KLog.e("查询有没有结果"+ (i==0) + i );
        if (i!=0){//没有查询结果
//            Messenger.getDefault().send(SpeechEvent.startSearch(),"SPEECH_TO_PAGE");
        }else{

        }
    }


    /**
     * 发送内容
     * @param asrResult
     * @throws RemoteException
     */
    @Override
    public void onQueryAsrResult(String asrResult) throws RemoteException {
        Messenger.getDefault().send(SpeechEvent.parResult(asrResult),"SPEECH_TO_PAGE");
        Log.i(TAG, " onQueryAsrResult :" + asrResult);
    }
}
